<template>
  <div class="app-container">
    <div>
      <parser :key="new Date().getTime()" :form-conf="detailForm" @submit="submitForm" />
    </div>
  </div>
</template>

<script>
import Parser from '@/components/parser/Parser'
import { getForm, publicSubmit } from '@/api/bpm/form'
import { getInfo } from '@/api/login'
import { decodeFields } from '@/utils/formGenerator'
// 流程实例的发起
export default {
  name: 'showForm',
  components: {
    Parser
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      formId: 0,
      // 流程表单详情
      detailForm: {
        fields: []
      }
    }
  },
  created() {
    this.formId = this.$route.query && this.$route.query.formId
    getForm(this.formId).then((response) => {
      const data = response.data

      this.detailForm = {
        ...JSON.parse(data.conf),
        fields: decodeFields(data.fields)
      }
    })
  },
  methods: {
    /** 提交按钮 ----*/
    submitForm(params) {
      getInfo().then((response) => {
        params.values = { ...params.values, ...{ createBy: response.user.userName } }
        console.log(params)
        publicSubmit('/Sleepfish/save', 'post', params).then((response) => {})
        if (response.code == 200) {
          this.$router.push({
            path: '/bpm/form'
          })
        }
      })
    }
  }
}
</script>

<style lang="scss"></style>
